<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/aaa/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/aaa/layuiadmin/style/admin.css" media="all">

    <!--
        时间：2018/12/25
        姓名：梁永振，
        描述：车辆回收页面
    -->
</head>
<body>
    <!--表单结构-->
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">手机号码：</label>
                        <div class="layui-input-block">
                            <input type="text" name="telphone" id="telephone" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button id="carrecycle-searchbtn" class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>

                    <div class="layui-inline">
                        <button class="layui-btn" id="history">历史记录</button>

                    </div>
                </div>
            </div>

            <div class="layui-card-body">
                <table class="layui-hide" id="carrecycle" lay-filter="carrecycle-filter"></table>

                <script src="/aaa/layuiadmin/layui/layui.js"></script>
                <script src="/aaa/layuiadmin/layui/layui-xtree.js"></script>

                <script type="text/html" id="carrecycle-bar">
                    <a class="layui-btn layui-btn-xs" lay-event="carrecycle-edit" id="price">价格</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="deal-del" id="deal">同意</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="refuse-del" id="refuse">驳回</a>
                </script>
            </div>
        </div>
    </div>
    <!--修改价格弹出层-->
    <div id="carrecycle-layer" style="display: none">

        <div class="layui-form-item">
            <input type="hidden" id="carrecycle-telephone" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">原价格(元)</label>
            <div class="layui-input-inline">
                <input type="text" id="carrecycle-oldcarexpense" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input  layui-disabled">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">新价格(元)</label>
            <div class="layui-input-inline">
                <input type="text" id="carrecycle-newcarexpense" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input"  onkeyup="this.value=this.value.replace(/[^0-9-]+/,'');">
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="button" value="保存" class="layui-btn" id="carrecycle-save"/>
                </div>
            </div>
        </div>

    </div>
    <!--历史弹出层-->
    <div class="layui-fluid"  id="carrecyclehistory-layer" style="display: none">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">手机号码：</label>
                        <div class="layui-input-block">
                            <input type="text" name="telphone" id="htelephone" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button id="carrecyclehis-searchbtn" class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>

                </div>
            </div>

            <div class="layui-card-body">
                <table class="layui-hide" id="carrecyclehistory" lay-filter="carrecycle-filter"></table>

            </div>
        </div>
    </div>


<script th:inline="none">
    /*------------------------------------------------------电动车回收表单---------------------------------------------------------*/
    layui.use(['table','form'], function() {
        var table = layui.table;
        var $ = layui.$;
        var form = layui.form;
        table.render({
            elem: '#carrecycle',
            height: 312,
            url: '/aaa/webrecycle/getAllCarList',
            page: true,
            cols: [
                [
                    {field: 'telephone', title: '手机号', align: 'center'},
                    {field: 'name', title: '申请人', align: 'center'},
                    {field: 'createtime', title: '申请时间', align: 'center'},
                    {field: 'carcode', title: '车辆出场号', align: 'center'},
                    {field: 'carexpense', title: '回收价格(￥)',
                        templet: function (d) {
                            if (d.carexpense == 0) {
                                return "<span style='color: palevioletred; font-size: 18px'>价格未设置</span>";
                            }else{
                                return "<span style='color: navy; font-size: 18px'>"+d.carexpense+"</span>";
                            }
                        },
                        align: 'center'},
                    {
                        field: 'carrecycleState', title: '回收状态',
                        templet: function (d) {
                            if (d.carrecycleState == 0) {
                                return "<span style='color: navy; font-size: 18px'>未处理</span>";

                            } else if (d.carrecycleState == 1) {
                                return "<span style='color: green; font-size: 18px'>已同意</span>";
                            } else {
                                return "<span style='color:red; font-size: 18px'>已驳回</span>";
                            }
                        },
                        align: 'center'
                    },
                    {title: '操作', toolbar: '#carrecycle-bar', align: 'center'}

            ]
            ]
        });
        /*********************************弹出层历史表单************************************************/
        layui.use(['table','form'], function() {
            var table = layui.table;
            var $ = layui.$;
            var form = layui.form;
            table.render({
                elem: '#carrecyclehistory',
                height: 312,
                url: '/aaa/webrecycle/getReCycleDetail',
                page: true,
                cols: [
                    [
                        {field: 'telephone', title: '手机号', align: 'center'},
                        {field: 'name', title: '申请人', align: 'center'},
                        {field: 'createtime', title: '申请时间', align: 'center'},
                        {field: 'carcode', title: '车辆出场号', align: 'center'},
                        {field: 'carexpense', title: '回收价格(￥)',
                            templet: function (d) {
                                if (d.carexpense == 0) {
                                    return "<span style='color: palevioletred; font-size: 18px'>价格未设置</span>";

                                }else{
                                    return "<span style='color: navy; font-size: 18px'>"+d.carexpense+"</span>";
                                }
                            },
                            align: 'center'},
                        {
                            field: 'carrecycleState', title: '回收状态',
                            templet: function (d) {
                                if (d.carrecycleState == 0) {
                                    return "<span style='color: navy; font-size: 18px'>未处理</span>";

                                } else if (d.carrecycleState == 1) {
                                    return "<span style='color: green; font-size: 18px'>已同意</span>";
                                } else {
                                    return "<span style='color:red; font-size: 18px'>已驳回</span>";
                                }
                            },
                            align: 'center'
                        },
                        {field: 'operator', title: '操作人', align: 'center'},
                        {field: 'updatetime', title: '最后的修改时间', align: 'center'}
                    ]
                ]
            });
        });
        /*end*/
        /*-----------------根据手机号搜索申请单------------------------*/
        $('#carrecycle-searchbtn').click(function () {
            table.reload('carrecycle', {
                url: '/aaa/webrecycle/getCarListByTel',
                where: {
                    telephone: $("#telephone").val()
                } //设定异步数据接口的额外参数
            });
        })


        /*-----------------根据手机号搜索历史------------------------*/
        $('#carrecyclehis-searchbtn').click(function () {
            table.reload('carrecyclehistory', {
                url: '/aaa/webrecycle/getCarHistoryByTel',
                where: {
                    telephone: $("#htelephone").val()
                } //设定异步数据接口的额外参数
            });
        })

        table.on('tool(carrecycle-filter)', function (obj) {
            var data = obj.data;
                //拒绝申请单
            if (obj.event === 'refuse-del') {
                layer.confirm('确定驳回申请吗？', function (index) {
                    $.post({
                        url: '/aaa/webrecycle/refuseApply',
                        traditional: true,
                        data: {
                            telephone: data.telephone
                        },
                    }, function (data) {
                        if (data.code == 100) {
                            layer.msg('申请单已驳回');
                            table.reload('carrecycle');
                        } else {
                            layer.msg("申请单驳回失败");
                        }
                    })
                });
                //完成申请单
            } else if (obj.event === 'deal-del') {
                layer.confirm('确定同意申请吗？', function (index) {
                    $.post({
                        url: '/aaa/webrecycle/dealApply',
                        traditional: true,
                        data: {
                            telephone: data.telephone
                        },
                    }, function (data) {
                        if (data.code == 100) {
                            $("#carrecycle-bar").val("已同意")
                            layer.msg('申请单已同意！');
                            table.reload('carrecycle');
                        } else {
                            layer.msg("同意操作失败！");
                        }
                    })
                });
            } else if (obj.event === 'carrecycle-edit') {
                $("#carrecycle-telephone").val(data.telephone);
                $("#carrecycle-oldcarexpense").val(data.carexpense);
                carrecyclelayer = layer.open({
                    type: 1,
                    title: '修改价格',
                    content: $('#carrecycle-layer')
                });
            }
        });

        /*---------------------------查看历史---------------------------------*/
        $('#history').click(function () {
            carrecycleDetaillayer = layer.open({
                type: 1,
                title: '历史记录',
                area: ['1500px', '550px'],
                content: $('#carrecyclehistory-layer')
            });
            //重新加载页面
            table.reload('carrecyclehistory', {
                url: '/aaa/webrecycle/getReCycleDetail',
                where: {
                }
            });
        })


        //保存价格修改
        $('#carrecycle-save').click(function () {

            if(  Number($("#carrecycle-newcarexpense").val()) < 0  ){
                layer.msg("价格不能为负数！");
            }else{
                var telephone = $("#carrecycle-telephone").val();
                var newcarexpense = $("#carrecycle-newcarexpense").val();
                $.post({
                    url: '/aaa/webrecycle/updatePrice',
                    traditional: true,
                    data: {
                        telephone: telephone,
                        carexpense: newcarexpense
                    },
                }, function (data) {
                    if (data.code == 100) {
                        $("#carrecycle-newcarexpense").val('');
                        layer.close(carrecyclelayer);
                        layer.msg("保存成功");

                        table.reload('carrecycle');
                    } else {
                        layer.close(carrecyclelayer);
                        layer.msg("保存失败");
                    }
                })
            }

        })
    });


</script>
</body>
</html>